home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cgraphix
/
kclippin.c
< prev
next >
Wrap
Text File
|
1986-05-28
|
2KB
|
117 lines
/* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
#include <stdio.h>
#define EXTERN extern
#include <typedef.h>
#define min(x,y) ((x < y) ? x : y)
#define max(x,y) ((x > y) ? x : y)
void SetClippingOn()
{
ClippingGlb = TRUE;
}
void SetClippingOff()
{
ClippingGlb = FALSE;
}
int clipping()
{
return(ClippingGlb);
}
static int inside(x,xx1,xx2)
int x, xx1, xx2;
{
if (x < xx1)
return(-1);
else if (x > xx2)
return(1);
return(0);
}
int clip(x1, y1, x2, y2)
int *x1, *y1, *x2, *y2;
{
int ix1, iy1, ix2, iy2, dummy, X1Loc, X2Loc, Y1Loc, Y2Loc;
int ClipLoc;
int retc;
ClipLoc = TRUE;
if (!ClippingGlb) {
return(ClipLoc);
}
ClipLoc = TRUE;
if (HatchGlb) {
X1Loc = min(X1RefGlb, X2RefGlb);
X2Loc = max(X1RefGlb, X2RefGlb);
}
else {
X1Loc = min(X1RefGlb * 8, X2RefGlb * 8 + 7);
X2Loc = max(X1RefGlb * 8, X2RefGlb * 8 + 7);
}
ix1 = inside(*x1, X1Loc, X2Loc);
ix2 = inside(*x2, X1Loc, X2Loc);
if (ix1 || ix2) {
if (*x1 != *x2) {
if (ix1 != 0) {
dummy = (ix1 < 0) ? X1Loc : X2Loc;
if (*y2 != *y1) {
*y1 = dblint(*y1 + (int)((double)(*y2 - *y1)
* (dummy - *x1) / (double)(*x2 - *x1)));
}
*x1 = dummy;
}
if ((ix2 != 0) && ( *x1 != *x2)) {
dummy = (ix2 < 0) ? X1Loc : X2Loc;
if (*y2 != *y1) {
*y2 = dblint(*y1 + (int)((double)(*y2 - *y1)
* (dummy - *x1) / (double)(*x2 - *x1)));
}
*x2 = dummy;
}
}
}
Y1Loc = min(Y1RefGlb, Y2RefGlb);
Y2Loc = max(Y1RefGlb, Y2RefGlb);
iy1 = inside(*y1, Y1Loc, Y2Loc);
iy2 = inside(*y2, Y1Loc, Y2Loc);
if (iy1 || iy2) {
if (*y1 != *y2) {
if (iy1 != 0) {
dummy = (iy1 < 0) ? Y1Loc : Y2Loc;
if (*x1 != *x2) {
*x1 = dblint(*x1 + (int)((double)(*x2 - *x1)
* (dummy - *y1) / (double)(*y2 - *y1)));
}
*y1 = dummy;
}
if ((iy2 != 0) && (*y1 != *y2)) {
dummy = (iy2 < 0) ? Y1Loc : Y2Loc;
if (*x1 != *x2) {
*x2 = dblint(*x1 + (int)((double)(*x2 - *x1)
* (dummy - *y1) / (double)(*y2 - *y1)));
}
*y2 = dummy;
}
}
}
if (inside(*y1,Y1Loc,Y2Loc) ||
inside(*y2,Y1Loc,Y2Loc) ||
inside(*x1,X1Loc,X2Loc) ||
inside(*x2,X1Loc,X2Loc)) {
ClipLoc = FALSE;
}
return(ClipLoc);
}